const toAboslute = (arr) => {
    let fromArr1 = []
    for(let i = 0; i < arr.length ; i++) {
        if(arr[i] === '..') {
            fromArr1.pop()
        }else if(arr[i] === '.') {
            
        }else{
            fromArr1.push(arr[i])
        }
    }
    return fromArr1
}
const getRelativePath = (to,from) => {
  let fromArr = from.split('/')
  let toArr = to.split('/')
  fromArr = toAboslute(fromArr)
  toArr = toAboslute(toArr)
  if(toArr[0] === '') toArr.shift()
  if(fromArr[0] === '') fromArr.shift()

  let i = 0
  for(; i < fromArr.length && i < toArr.length; i++) {
    if(fromArr[i] !== toArr[i]) break
  }
  let ans = ''
  ans = fromArr.slice(i).map(() => '..').join('/') 
  if(ans !== '') ans += '/'
  ans += toArr.slice(i).join('/')
  return ans
}


const ans = getRelativePath('/home/a/b/c', '/home/a/x/y')
const ans1 = getRelativePath('/home/b/c', '/home/x/y')
const ans2 = getRelativePath('/home/c', '/home/y')
const ans3 = getRelativePath('/home', '/home')
const ans4 = getRelativePath('/home/a', '/home')
const ans5 = getRelativePath('/home', '/home/b')
const ans6 = getRelativePath('/home', '/dev')
const ans7 = getRelativePath('/', '/')
const ans8 = getRelativePath('/home/./../a', '../home')




console.log(ans,ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8)
